<template>
    <div class="SimpleTalk-page">
        <div class="turn">
            <div class="SimpleTalklist">
                <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
                <van-list
                  v-model="loading"
                  :finished="finished"
                  @load="onLoad"
                >
                <router-link tag="div" :to="'/simpletalk?id='+item.id" class="SimpleTalkItem" v-for="item in list" :key="item.id">
                    <div class="mainCon" v-if="item.attachment==null">
                        <div class="img">
                        <img :src="'https://pic.ecook.cn/web/'+ item.imageids +'.jpg!wl280'" v-lazy="'https://pic.ecook.cn/web/'+ item.imageids +'.jpg!wl280'" alt="">
                    </div>
                    <div class="text line-ellipsis4">{{item.text}}</div>
                    </div>
                    <div class="mainCon attachment" v-else>
                        <div class="title">{{item.attachment.title}}</div>
                        <div class="imgCon">
                            <img :src="'https://pic.ecook.cn/web/'+ item.attachment.imageid +'.jpg!wl280'" v-lazy="'https://pic.ecook.cn/web/'+ item.attachment.imageid +'.jpg!wl280'" alt="">
                            <div class="name">{{item.attachment.title}}</div>
                        </div>
                    </div>
                    <div class="other">
                        <div class="yuan"></div>
                        <div class="line"></div>
                    </div>
                    <div class="time" v-if="item.displaytime.length>10">{{item.displaytime | Time}}</div>
                    <div class="time" v-else>{{item.displaytime}}</div>
                </router-link>
                </van-list>
                </van-pull-refresh>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    props:["simpleTalkList"],
    data() {
        return {
            list: [],
            loading: false,
            finished: false,
            refreshing: false,
            num:0,
        };
    },

    methods: {
    onLoad() {
      setTimeout(() => {
        if (this.refreshing) {
          this.list = [];
          this.refreshing = false;
          this.num = 0
        }

        if (this.simpleTalkList.length>=10) {
          for (let i = this.num; i < this.num + 10; i++) {
            if (this.simpleTalkList[i]!=undefined) {          
              this.list.push(this.simpleTalkList[i]);
            }
          }
        }else if(this.simpleTalkList.length<10){
          for (let i = this.num; i < this.simpleTalkList.length; i++) {
            this.list.push(this.simpleTalkList[i]);
          }
        }
      
        this.num += 10
        this.loading = false;

        if (this.list.length >= this.simpleTalkList.length) {
          this.finished = true;
        }
        }, 500);
    },
    onRefresh() {
        // 清空列表数据
        this.finished = false
        // 重新加载数据
        // 将 loading 设置为 true，表示处于加载状态
        this.loading = true;
        this.onLoad();
    },
   },
   filters:{
    Time(value){
        if (value) {
            let time = value.split(" ")[0]
            let m = time.split("-")[0]
            let d = time.split("-")[1]
            return `${m}月${d}日`
        }
    }
   }
};
</script>

<style lang="less" scoped>
.SimpleTalk-page{
    width: 100%;
    background-color: #f2f2f2;

    .turn{
        margin-top: 25px;

        .SimpleTalklist{
            padding: 15px;

            .SimpleTalkItem{
                width: 100%;
                height: 200px;
                display: flex;
                align-items: center;
                position: relative;
                margin-bottom: 1px;
                .mainCon{
                    width: 100%;
                    height: 110px;
                    padding: 15px;
                    box-sizing: border-box;
                    background-color: #fff;
                    border-radius: 8px;
                    display: flex;
                    position: relative;
                    z-index: 10;


                    .img{
                        flex:0 0 90px;
                        height: 100%;
                        margin-right: 15px;
                    }
                    .text{
                        font-weight: bold;
                        line-height: 20px;
                        font-size: 14px;
                        letter-spacing: 0.5px;
                    }
                }
                .other{
                    width: 100px;
                    position: absolute;
                    left: 15px;
                    height: 100%;
                    overflow: hidden;

                    .yuan{
                        width: 20px;
                        height: 20px;
                        border-radius: 50%;
                        background-color: #999;
                    }
                    .line{
                        width: 6px;
                        height: 100%;
                        background-color: #999;
                        margin-left: 7.5px;
                        margin-top: -1px;
                    }
                }
                .time{
                    position: absolute;
                    top: 4px;
                    left: 45px;
                    font-size: 15px;
                    letter-spacing: 0.5px;
                    font-weight: bold;
                    color: #666;
                }
                .attachment{
                    display: flex;
                    flex-direction: column;
                    height: 120px;
                    .title{
                        font-weight: bold;
                        font-size: 14px;
                        letter-spacing: 0.5px;
                        margin-bottom: 15px;

                    }
                    .imgCon{
                        display: flex;
                        width: 100%;
                        background-color: #f2f2f2;
                        align-items: center;
                        &>img{
                            width: 60px;
                            height: 60px;
                            display: block;
                            margin-right: 20px;
                        }
                        .name{
                            font-weight: bold;
                            font-size: 14px;
                            color: #666;
                            letter-spacing: 0.5px;
                        }
                    }
                }
            }
        }
    }
}
</style>